package writeor.aidraw.config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import writeor.aidraw.inteceptor.login_inteceptor;

@Configuration
public class MyMVCConfig implements WebMvcConfigurer {
    @Autowired
    private login_inteceptor login_inteceptor;

//    @Override
//    public void addViewControllers (ViewControllerRegistry registry){
////        registry.addViewController("/toLoginPage").setViewName("login");
////        registry.addViewController("/login.html").setViewName("login");
//
//    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry.addInterceptor(inteceptor1).addPathPatterns("/**").excludePathPatterns("/login");
        //registry.addInterceptor(inteceptor2).addPathPatterns("/toLoginPage");

        InterceptorRegistration registration = registry.addInterceptor(login_inteceptor);
        registration.addPathPatterns("/**"); //所有路径都被拦截
        registration.excludePathPatterns( //添加不拦截路径
                "/",
                "/ImageDetail/**",
                "/Image_detail/**",
                "/toRegister",
                "/register",
                "/index",
                "/toLogin", //登录页面
                "/login",       //登录请求
                "/**/*.html",   //html静态资源
                "/**/*.js",     //js静态资源
                "/**/*.png",
                "/images/*.png",
                "/**/*.css"     //css静态资源
        );
    }
    //解决刷新后才显示图片的问题
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/**").addResourceLocations("file:F:/novel-naifu-aki/AiDraw/src/main/resources/static/images/");
    }

}
